<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        function fullpermutate(str) {
            var result = [];
            if (str.length > 1) {
                //遍历每一项
                for (var m = 0; m < str.length; m++) {
                    //拿到当前的元素
                    var left = str[m];
                    //除当前元素的其他元素组合
                    var rest = str.slice(0, m) + str.slice(m + 1, str.length);
                    //上一次递归返回的全排列
                    var preResult = fullpermutate(rest);
                    //组合在一起
                    for (var i = 0; i < preResult.length; i++) {
                        var tmp = left + preResult[i]
                        result.push(tmp);
                    }
                }
            } else if (str.length == 1) {
                result.push(str);
            }
            return result;
        }

    </script>
</body>

</html>